package ylyhappy.com.javaguidemo.controllers

import javafx.event.ActionEvent
import javafx.fxml.FXML
import javafx.fxml.FXMLLoader
import javafx.scene.Node
import javafx.scene.Parent
import javafx.scene.Scene
import javafx.scene.control.PasswordField
import javafx.scene.control.TextField
import javafx.stage.Stage
import ylyhappy.com.javaguidemo.HelloApplication

class LoginController {

    @FXML
    private lateinit var passwdInput: PasswordField

    @FXML
    private lateinit var usernameInput: TextField
    @FXML
    fun LoginAndRegister(event: ActionEvent) {
        val username = usernameInput.text
        val passwd = passwdInput.text

        if (username == "ylyhappy" && passwd == "hello") {
            val stage = (event.source as Node).scene.window as Stage
            stage.hide();
            val fxmlLoader = FXMLLoader(HelloApplication::class.java.getResource("javafx-demo.fxml"))
            val scene = Scene(fxmlLoader.load(), 900.0, 600.0)
            scene.stylesheets.add(HelloApplication::class.java.getResource("test.css").toExternalForm());
            stage.scene = scene
            stage.show()
        }
    }
}